<template>
  <!-- 页面顶端的导航组件  -->
  <div class="nav-bar">
    <div class="left" @click="goBack">
      <slot name="left">
        <!-- 后退的箭头 +事件 -->
        <ArrowLeft />
      </slot>
    </div>
    <div class="center">
      <slot></slot>
      <!-- 默认插槽-->
    </div>
    <div>
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script>
import { useRouter } from "vue-router";
import { ArrowLeft } from "@element-plus/icons-vue";

export default {
  components: {
    ArrowLeft,
  },
  setup() {
    const router = useRouter();
    const goBack = () => {
      router.go(-1);
    };
    return {
      goBack,
    };
  },
};
</script>

<style  scoped>
.nav-bar {
  background-color: #42b983;
  color: #ffffff;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 9;
  height: 45px;
  line-height: 45px;
  box-shadow: 0 5px 5px rgba(100, 100, 100, 0.2);
  display: flex;
  .left,
  .right {
    width: 10px;
  }
  .center {
    flex: 1;
  }
}
</style>
